home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
tex
/
texsrc.arc
/
EXTRA.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-09-14
|
22KB
|
809 lines
/*
* Hand-coded routines for C TeX.
* This module should contain any system-dependent code.
*
* This code was written by Tim Morgan, drawing from other Unix
* ports of TeX.
* hacked up for MEGAMAX-C on ATARI ST by David Dermott
*/
/*#define CATCHINT*/ /* Catch ^C's */
/*#undef SYSV */ /* Turn on System V compatibility */
/*#define BSD */ /* 4.[23]BSD */
#define EXTERN /* Actually instantiate globals here */
#include "texd.h"
#include <osbind.h> /* st os routines */
#ifdef CATCHINT
#include <signal.h>
#endif
#ifdef BSD
#include <sys/time.h>
#else
#include <time.h>
#endif
/*#if defined(BSD)||defined(SYSV)
#include <sgtty.h>
#endif
*/
#ifdef VMS
#define index strchr /* Sys V compatibility */
#endif
/* C library stuff that we're going to use */
extern char *strcpy(), *strcat(), *malloc(), *sprintf(), *index(), *getenv();
/* Local stuff */
static int gargc;
static char **gargv;
static char texformats[filenamesize], texinputs[filenamesize];
static char texfonts[filenamesize], texpool[filenamesize];
static char my_realnameoffile[filenamesize];
/*static char *texeditvalue = "/usr/ucb/vi +%d %s";*/
static char *texeditvalue = "EMACS.TTP -g%d %s";
#define TRUE 1
#define FALSE 0
#ifdef CATCHINT
/* If we're catching ^C, come here when one comes in. */
static catchint()
{
interrupt = 1;
(void) signal(SIGINT, catchint);
}
#endif
/* Do the obvious */
get_date_and_time(minutes, day, month, year)
integer *minutes, *day, *month, *year;
{
long clock, time();
struct tm *tmptr, *localtime();
clock = time((long *) 0);
tmptr = localtime(&clock);
*minutes = tmptr->tm_hour * 60 + tmptr->tm_min;
*day = tmptr->tm_mday;
*month = tmptr->tm_mon + 1;
*year = tmptr->tm_year + 1900;
#ifdef CATCHINT
(void) signal(SIGINT, catchint);
#endif
}
#ifdef INITEX
/* Read until we pass end of line on the input file, a la Pascal */
readln(f)
FILE *f;
{
register int c;
do
c = getc(f);
while (c != '\n' && c != EOF);
}
/* Same as in Pascal --- return TRUE if EOF or next char is newline */
eoln(f)
FILE *f;
{
register int c;
if (feof(f)) return(TRUE);
c = getc(f);
if (c != EOF)
(void) ungetc(c, f);
return (c == '\n' || c == EOF);
}
#endif /* INITEX */
static void copy_path(ptr, defptr, override)
char *ptr, *defptr, *override;
{
if (override) {
if (strlen(override) >= 1024) {
(void) fprintf(stderr, "Path too long\n");
exit(1);
}
(void) strcpy(ptr, override);
}
else
(void) strcpy(ptr, defptr);
}
/* Initialize path variables for loading fonts and things */
setpaths()
{
copy_path(texformats, TEXFORMATS, getenv("TEXFORMATS"));
copy_path(texinputs, TEXINPUTS, getenv("TEXINPUTS"));
copy_path(texfonts, TEXFONTS, getenv("TEXFONTS"));
copy_path(texpool, TEXPOOL, getenv("TEXPOOL"));
}
/*
* The following procedure is due to sjc@s1-c.
*
* calledit(filename, fnstart, fnlength, linenumber)
*
* TeX82 can call this to implement the 'e' feature in error-recovery
* mode, invoking a text editor on the erroneous source file.
*
* You should pass to "filename" the first character of the packed array
* containing the filename, and to "fnstart" and "fnlength" the index and
* length of the filename as it appears inside that array.
*
* Ordinarily, this invokes "/usr/ucb/vi". If you want a different
* editor, create a shell environment variable TEXEDIT containing
* the string that invokes that editor, with "%s" indicating where
* the filename goes and "%d" indicating where the decimal
* linenumber (if any) goes. For example, a TEXEDIT string for a
* variant copy of "vi" might be:
*
* setenv TEXEDIT "/usr/local/bin/vi +%d %s"
*
*/
calledit(filename, fnstart, fnlength, linenumber)
ASCIIcode filename[];
poolpointer fnstart;
integer fnlength, linenumber;
{
char *temp, *command, c;
int sdone, ddone, i;
/* close all input files */
for (i=1;i<= inopen;i++)fclose(inputfile[i]);
/* so they can be editted */
freemem();/* free some memory*/
sdone = ddone = 0;
filename += fnstart;
/* Replace default with environment variable if possible. */
if (NULL != (temp = getenv("TEXEDIT")))
texeditvalue = temp;
/* Make command string containing envvalue, filename, and linenumber */
if (NULL ==
(command = (char *) malloc((unsigned) strlen(texeditvalue) + (int)fnlength
+ 25))) {
(void) fprintf(stderr, "! Not enough memory to issue editor command\n");
exit(1);
}
temp = command;
while ((c = *texeditvalue++) != '\0') {
if (c == '%') {
switch (c = *texeditvalue++) {
case 'd':
if (ddone) {
(void) fprintf(stderr,
"! Line number cannot appear twice in editor command\n");
exit(1);
}
(void) sprintf(temp, "%d", (int)linenumber);
while (*temp != '\0')
temp++;
ddone = 1;
break;
case 's':
if (sdone) {
(void) fprintf(stderr,
"! Filename cannot appear twice in editor command\n");
exit(1);
}
i = 0;
while (i < fnlength)
*temp++ = filename[i++];
sdone = 1;
break;
case '\0':
*temp++ = '%';
texeditvalue--; /* Back up to \0 to force termination. */
break;
default:
*temp++ = '%';
*temp++ = c;
break;
}
}
else
*temp++ = c;
}
*temp = '\0';
/* Execute command. */
if (system(command))
(void) fprintf(stderr, "! Trouble executing command %s\n", command);
/* Quit, indicating TeX found an error */
exit(1);
}
/*
* Change a Pascal-like filename into a C-like string.
* If running on a non-ASCII system, will have to use xchr[]
* array to convert from internal character set (in the "nameoffile"
* array) into the enternal character set (in "realnameoffile").
* "nameoffile" is an array indexed starting with 1, so we add 1
* to all references to point to the first character in the name.
*/
static packrealnameoffile(prefix)
char *prefix;
{
register char *cp, *p, *q;
p = prefix;
for (q = my_realnameoffile; p && *p && *p != ';'; *q++ = *p++);
if (prefix && *prefix)
*q++ = '\\';
for (cp = nameoffile+1, p = realnameoffi + 1; *cp != ' ' && *cp;)
#ifdef NONASCII
*q++ = xchr[*p++ = *cp++];
#else
*q++ = (*p++ = *cp++);
#endif
*p = ' ';
*q = '\0';
}
/* Open an input file f */
Openin(f, pathspec,fmode)
FILE **f;
int pathspec;
char fmode[];
{
register char *prefix, *nprefix;
register char *cp;
/*printf("name %s mode %s path %d ",&nameoffile[1],fmode,pathspec);*/
switch (pathspec) {
case inputpathspec:
case readpathspec:
prefix = texinputs;
break;
case fontpathspec:
prefix = texfonts;
break;
case poolpathspec:
prefix = texpool;
break;
case fmtpathspec:
prefix = texformats;
break;
default: /* "Can't" happen */
(void) fprintf(stderr, "INTERNAL CONFUSION---IMPLEMENTATION ERROR\n");
exit(1);
}
/*printf(" %s \n",prefix);*/
if ((nameoffile[2] == ':')||(nameoffile[1] == '/')) {/* Absolute pathname */
for (cp = nameoffile+1; *cp && *cp != ' '; ++cp);
*cp = '\0';
/*printf("absolute %s\n",nameoffile);*/
cnvtfn(nameoffile+1);
if (*f = fopen(nameoffile+1, fmode)) {
(void) strcpy(realnameoffi + 1, nameoffile+1);
(void) strcat(realnameoffi + 1, " ");
if (pathspec == fontpathspec)
tfmtemp = getc(*f); /* Simulate readahead */
return (1);
}
return (0);
}
/* Else relative pathname */
while (prefix) {
packrealnameoffile(prefix);
/*printf("try %s %s\n",my_realnameoffile,prefix);*/
cnvtfn(my_realnameoffile);
*f = fopen(my_realnameoffile, fmode);
if (*f) {
(void) strcpy(realnameoffi + 1, my_realnameoffile);
(void) strcat(realnameoffi + 1, " ");
if (pathspec == fontpathspec)
tfmtemp = getc(*f); /* Simulate Pascal readahead */
return (1);
}
nprefix = index(prefix, ';');
if (nprefix)
prefix = nprefix + 1;
else
break;